﻿namespace Web.Control.WWW.Partner
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections;

    using Lx.Web.Common.ControlsUI;    
    using System.Collections.Generic;
    using System.Reflection;
    /// <summary>
    /// 搜索会员2
    /// </summary>
    public class Search2 : BaseControl
    {
        /// <summary>
        /// 当前会员号
        /// </summary>
        string memberno = "";
        /// <summary>
        /// 详细列表大小
        /// </summary>
        protected Literal litCount;        
        protected Repeater rptUserList;        
        protected Repeater rptPopular;
        protected int RecordCount = 0;
        protected int PageIndex = 1;
        protected int psize = 20;       
        /// <summary>
        /// 根据兴趣爱好搜索会员
        /// </summary>
        protected int Favorite = 0;
        /// <summary>
        /// 根据当前所在国家搜索会员
        /// </summary>
        protected string Country = "";

        protected override void OnLoad(EventArgs e)
        {
            ArrayList arrList = new ArrayList();
            memberno = HttpContext.Current.User.Identity.Name;

            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["p"] == "L")
                {
                    PageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out PageIndex);
                }
            }
            if (!string.IsNullOrEmpty(Request["favorite"]))
            {
                int.TryParse(Request["favorite"], out Favorite);
            }
            else if (!string.IsNullOrEmpty(Request["country"]))
            {
                Country = Request["country"];
            }
            int.TryParse(litCount.Text, out psize);
            if (Country != "")
                arrList = BLF.WWW_WWW.Contact.Contacts.GetPartner_Country(Country, memberno, PageIndex, psize);
            else
                arrList = BLF.WWW_WWW.Contact.Contacts.GetPartner_Favorite(Favorite, memberno, PageIndex, psize);
            if (arrList != null)
            {
                RecordCount = (int)arrList[0];
                int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)psize));
                if (PageIndex > pCount) PageIndex = pCount;

                if (rptUserList != null)
                {
                    rptUserList.DataSource = arrList[1];
                    rptUserList.DataBind();
                }
                if (rptPopular != null)
                {
                    List<BLF.LanguageObj> lanObjList = new List<BLF.LanguageObj>();
                    lanObjList.AddRange(BLF.StaticData.GetPopLanguageList);
                    rptPopular.DataSource = lanObjList;
                    rptPopular.DataBind();
                }
                //title
                this.DynamicDescription = GetText("Find a Language Partner for language exchange, or find a language teacher at italki");
                if (!string.IsNullOrEmpty(Request["favorite"]))
                {
                    this.DynamicTitle = GetText("Find a Language Exchange Partner - {0} - italki", new string[] { BLF.WWW_WWW.Contact.Contacts.GetFavorite(Favorite) });
                    this.DynamicKeywords = GetText("language exchage, {0}", new string[] { BLF.WWW_WWW.Contact.Contacts.GetFavorite(Favorite) });
                }
                else
                {
                    this.DynamicTitle = GetText("Find a Language Exchange Partner - living in {0} - italki", new string[] { BLF.StaticData.GetCountryText(Country) });
                    this.DynamicKeywords = GetText("language exchage, {0}", new string[] { BLF.StaticData.GetCountryText(Country) });
                }
            }
            else {
                Response.End();
                return;
            }
            base.OnLoad(e);
        }     
    }
}
